
package ui.activity.poscontrol.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Utils.StringUtil;
import ui.activity.poscontrol.beanmodel.PushPosBean;


/**
 *POS查询列表适配器
 * Created by chenjian on 19/2/27
 */
public class HasPushPosRecordAdapter extends DelegateAdapter.Adapter<HasPushPosRecordAdapter.ProfitVH> {

    private final Context mContext;
    private List<PushPosBean.RecordsBean> mData = new ArrayList<>();//数据

    public HasPushPosRecordAdapter(Context context,List<PushPosBean.RecordsBean> mdata) {
        mContext = context;
        if (mdata != null) {
            mData.addAll(mdata);
        }
    }

    public void setupData(List<PushPosBean.RecordsBean> data) {
        mData.clear();
        if (data != null) {
            mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    public List<PushPosBean.RecordsBean> getData() {
        return mData;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitVH(LayoutInflater.from(mContext).inflate(R.layout.layout_haspush_device, viewGroup, false));
    }




    @Override
    public void onBindViewHolder(@NonNull ProfitVH holder, int position) {
        PushPosBean.RecordsBean bean = mData.get(position);
        holder.queryArrow.setVisibility(View.GONE);
        holder.index.setText((position+1) + "");
        holder.sn.setText(bean.getPosSn()+"");
        holder.status.setTextColor(mContext.getResources().getColor(R.color.tc_333333));
        if ("4".equals(bean.getActiveStatus())) {
            holder.status.setText("已开通");
        } else if ("3".equals(bean.getActiveStatus())) {
            holder.status.setText("审核失败");
            holder.status.setTextColor(mContext.getResources().getColor(R.color.red_ff0000));
        } else if ("".equals(bean.getActiveStatus())) {
            holder.status.setText("未开通");
        } else if ("2".equals(bean.getActiveStatus())) {
            holder.status.setText("审核中");
        } else if ("5".equals(bean.getActiveStatus())) {
            holder.status.setText("已激活");
        }else if ("6".equals(bean.getActiveStatus())) {
            holder.status.setText("已达标");
        }else{
            holder.status.setText("未开通");
        }
        holder.returnmoney.setText(StringUtil.getFormatPriceInt(bean.getBackAmount())+"元");
//        if(null == bean.getActiveStatus()||"null".equals(bean.getActiveStatus())||Integer.parseInt(bean.getActiveStatus())<5){
//            holder.returnmoney.setTextColor(mContext.getResources().getColor(R.color.blue_0ca6f0));
//            holder.returnmoney.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent = new Intent(mContext, ChangeBackAct.class);
//                    intent.putExtra("sn",bean.getPosSn()+"");
//                    mContext.startActivity(intent);
//                }
//            });
//        }else{
//            holder.returnmoney.setTextColor(mContext.getResources().getColor(R.color.tc_333333));
//        }


    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class ProfitVH extends RecyclerView.ViewHolder {
        View wrap;
        TextView index;
        TextView sn;
        TextView status;
        ImageView queryArrow;
        View childLayout;
        TextView merchantNumber;
        TextView rate;
        TextView phone;
        TextView name;
        TextView returnmoney;
        ProfitVH(@NonNull View itemView) {
            super(itemView);
            wrap = itemView.findViewById(R.id.wrap);
            returnmoney = itemView.findViewById(R.id.returnmoney);
            index = itemView.findViewById(R.id.index);
            sn = itemView.findViewById(R.id.sn);
            status = itemView.findViewById(R.id.open_status);
            queryArrow = itemView.findViewById(R.id.query_arrow);
            childLayout = itemView.findViewById(R.id.child_layout);
             merchantNumber = itemView.findViewById(R.id.merchant_number);
             rate = itemView.findViewById(R.id.rate);
             phone = itemView.findViewById(R.id.phone);
             name = itemView.findViewById(R.id.name);
        }
    }
}
